
#include "Tiles.h"



/* initializes tiles (floor, wall, hole)
 *   level_design: an array of ints which correspond to tile types
 *   @return: 0 if SUCCESS, 1 if FAIL
 */
void Tiles::initialize(int** level_design){
	columns = 0;
	rows = 0;
	int tmp = 0;
	string tmp_name;
	
	// Determines the size of the level (i.e. 5x5 map, or 10x15)
	//  -- right now only works with rectangles (each row cannot have different number of tiles)
	while(level_design[columns][rows] != NONE) {
		rows++;
	}
	while(level_design[columns][0] != NONE) {
		columns++;
	}

	// test // cout << "column,row" << endl << columns << endl << rows << endl;

	//initiates an array of tile structs
	// NEXT PART. HOW TO INITIALIZE tile_t STRUCTS?
	// GLOBAL VARIABLE? NO...a class member?
	map.resize(columns*rows+1);

	int r_tmp = 0;
	int c_tmp = 0;
	max_map = 0;

	while(c_tmp < columns){
		r_tmp = 0;
		while(level_design[c_tmp][r_tmp] != NONE ) {
			init_tile(level_design[c_tmp][r_tmp],max_map);
			max_map++;
			r_tmp++;
			}
		c_tmp++;
	}

	/*Test
	tmp = 0;
	while( tmp < max_map ) {
		cout << tmp << " " << map[tmp].name << endl;
		tmp++;
	}
	while(1);*/
}
	
	// Function initializes one tile in the map
	//	tile_type: an (enum)integer showing if FLOOR, WALL, or HOLE
	//	index: the index/tile of the map
	//		-need to put in return values and walkability?
	int Tiles::init_tile(int tile_type, int index) {
		if(tile_type == FLOOR){
			map[index].name = "floor";
			map[index].pic = 1;
		} else if(tile_type == WALL){
			map[index].name = "wall";
			map[index].pic = 0;
		} else if(tile_type == HOLE){
			map[index].name = "hole";
			map[index].pic = 8;
		}

		return 0;
	}


	// Shotty map GUI
	int Tiles::show_map(){
		int tmp = 0;
		cout << endl;

		while( tmp < max_map ) {
			// if end of row, endl
			if( tmp % rows == 0 ){
				cout << endl;
			}
			cout << " " << map[tmp].pic;
			tmp++;
		}
	while(1);
	}